<template>
  <div style="width: 100%;" class="f-column-Wcenter">
    <div class="header" style="width: 98%;">
     <div style="width: 50%;margin: 20px 0;" class="f-row-Hcenter">
       <el-input style="width: 200px;" v-model="query1.company" placeholder="公司名称"></el-input>
      <!-- <el-dropdown style="margin-left: 30px;" @command="handleCommand1">
         <el-button type="primary">
           {{query1.command}}<i class="el-icon-arrow-down el-icon--right"></i>
         </el-button>
         <el-dropdown-menu slot="dropdown">
           <el-dropdown-item command="0">全部</el-dropdown-item>
           <el-dropdown-item command="1">草稿</el-dropdown-item>
           <el-dropdown-item command="2">审核中</el-dropdown-item>
           <el-dropdown-item command="3">审批通过</el-dropdown-item>
           <el-dropdown-item command="4">审批不通过</el-dropdown-item>
         </el-dropdown-menu>
       </el-dropdown> -->
       <el-button style="margin-left: 30px;" type="primary" icon="el-icon-search" @click="getTable(1)">搜索</el-button>
     </div>
    </div>
    <div class="table-box">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column fixed prop="company" label="公司名称" width="220">
          <template slot-scope="scope">
            <div style="width:200px; white-space:nowrap; text-overflow:ellipsis; overflow: hidden; ">
              {{scope.row.company}}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="authorize" label="授权人" width="120">
        </el-table-column>
        <el-table-column prop="phone" label="授权人电话" width="190">
        </el-table-column>
        <el-table-column prop="createTime" label="申请时间" width="200">
        </el-table-column>
        <el-table-column prop="address" label="项目状态" width="300">

          <template slot-scope="scope">
            <div v-if="scope.row.status ==6" class="f-row-Wcenter" style="color:#ff8f0f;">
              {{scope.row.applyIstoStatus == 1 ?'上链审核中':''}}
              {{scope.row.applyIstoStatus == 2 ?'上链审核通过':''}}
              {{scope.row.applyIstoStatus == 3 ?'上链审核不通过':''}}
              {{scope.row.applyIstoStatus == 4 ?'资产抵押中':''}}
              {{scope.row.applyIstoStatus == 5 ?'资产抵押通过':''}}
              {{scope.row.applyIstoStatus == 6 ?'资产抵押不通过':''}}
              {{scope.row.applyIstoStatus == 7 ?'发行申请中':''}}
              {{scope.row.applyIstoStatus == 8 ?'发行申请通过':''}}
              {{scope.row.applyIstoStatus == 9 ?'发行申请不通过':''}}
              {{scope.row.applyIstoStatus == 10 ?'发行资产':''}}
            </div>
            <div v-else   class="f-row-Wcenter" style="color:#ff8f0f;">
              {{scope.row.status == 0 ?'草稿':''}}
              {{scope.row.status == 1 ?'初审中':''}}
              {{scope.row.status == 2 ?'初审不通过':''}}
              {{scope.row.status == 3 ?'初审通过':''}}
              {{scope.row.status == 4 ?'复审中':''}}
              {{scope.row.status == 5 ?'复审不通过':''}}
              {{scope.row.status == 6 ?'复审通过':''}}
              {{scope.row.status == 7 ?'需要重新申请':''}}
            </div>

          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" class="f-row-Hcenter">
          <template slot-scope="scope" >
            <div class="f-row-Hcenter">
            <el-button @click="handleClick(scope.row)" type="text" size="small">详情</el-button>
              <div @click="toPage(scope.row)" >
                <div v-if="scope.row.status ==6" class="f-row-Wcenter"  style="color:#0392ff; margin-left: 10px;">
                  {{scope.row.applyIstoStatus == 1 ?'上链审核中':''}}
                  {{scope.row.applyIstoStatus == 2 ?'上链审核通过':''}}
                  {{scope.row.applyIstoStatus == 3 ?'上链审核不通过':''}}
                  {{scope.row.applyIstoStatus == 4 ?'资产抵押中':''}}
                  {{scope.row.applyIstoStatus == 5 ?'资产抵押通过':''}}
                  {{scope.row.applyIstoStatus == 6 ?'资产抵押不通过':''}}
                  {{scope.row.applyIstoStatus == 7 ?'发行申请中':''}}
                  {{scope.row.applyIstoStatus == 8 ?'发行申请通过':''}}
                  {{scope.row.applyIstoStatus == 9 ?'发行申请不通过':''}}
                  {{scope.row.applyIstoStatus == 10 ?'发行资产':''}}
                </div>
                <div v-else   class="f-row-Wcenter" style="color:#0392ff;margin-left: 10px;">
                  {{scope.row.status == 0 ?'草稿':''}}
                  {{scope.row.status == 1 ?'初审中':''}}
                  {{scope.row.status == 2 ?'初审不通过':''}}
                  {{scope.row.status == 3 ?'初审通过':''}}
                  {{scope.row.status == 4 ?'复审中':''}}
                  {{scope.row.status == 5 ?'复审不通过':''}}
                  {{scope.row.status == 6 ?'复审通过':''}}
                  {{scope.row.status == 7 ?'需要重新申请':''}}
                </div>
              </div>

              </div>
          </template>

        </el-table-column>
      </el-table>
      <div style="width: 100%;margin-top: 20px;" class="f-row-Wcenter">
        <el-pagination background layout="prev, pager, next" :page-size="query1.pageSize" :total="query1.total"
          @prev-click="onprevclick" @next-click="onnextclick" @current-change="onCurrentChange">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import serveApi from "@/api/serveApi"
  export default {


    data() {
      return {
        query1: {
          command :'全部',
          company: '', //string企业名称
          end: '', // string($date-time)

          start: '', //string($date-time)
          status: '', //string状态0草稿，1初审中，2初审不通过，3初审通过，4复审中，5复审不通过，6复审通过


          pageNum: 1, //integer($int32)页码
          pageSize: 6, //integer($int32)每页大小
          currentPage: 0, //当前页数
          totalPage: 1, //总页数
          total: 0, //总条数条数
          toastTitle: false, //显示加载
        },
        tableData: []
      }
    },
    mounted() {
      this.userId = this.$store.state.userInfo.id;
      this.getTable(1);
    },
    methods: {
      handleClick(row) {
        console.log(row);
        // this.$route.push({path:'/projects_details',params:row})

        this.$router.push({
          name: "projects_details",
          query: row
        })
      },
      getTable(pageNum) {
        let that = this;
        if (pageNum > 0) {
          that.query1.pageNum = pageNum;
        }
        // if (that.uid) {
        //   that.query1.userId = that.uid;
        // } else {
        //   that.$message.error('userId为空')
        //   return;
        // }

        serveApi.applySto_selectByPage(this.query1).then(res => {
          if (res.status === "0000") {
            if (res.data) {
              //分页请求
              that.tableData = res.data;
              that.query1.totalPage = res.pages;
              that.query1.total = res.total;
              if (that.query1.currentPage >= that.query1.totalPage) {
                that.query1.toastTitle = true;
              } else {
                that.query1.toastTitle = false;
                that.query1.currentPage = that.query1.pageNum;
                that.query1.pageNum = that.query1.pageNum + 1;
              }
            }
          } else {
            that.$message.error(res.message);
          }
        });

      },
      onprevclick() {
        this.query1.currentPage = this.query1.currentPage - 1;
        this.query1.pageNum = this.query1.currentPage;
        this.getTable();
      },
      onnextclick() {
        this.getTable();
      },
      onCurrentChange(e) {
        this.getTable(e);
      },
      handleCommand1(command) {
        this.query1.status = command;
        if (this.query1.status == 0) {
          this.query1.command = '全部';
          delete this.query1.status;
        }
        if (this.query1.status == 1) {
          this.query1.command = '草稿';
        }
        if (this.query1.status == 2) {
          this.query1.command = '审核中';
        }
        if (this.query1.status == 3) {
          this.query1.command = '审批通过';
        }
        if (this.query1.status == 4) {
          this.query1.command = '审批不通过';
        }

      },
      toPage(row){
        console.log(row)
        if(row.status == 6){
           if(row.applyIstoStatus == 1){
            // 上链定价
               this.$router.push({name:'users-Customer/projects/projects-OnPricing/onPricing', query: row});
           }
           if(row.applyIstoStatus == 4){
            // 资产抵押
               this.$router.push({name:'users-Customer/projects/projects-OnPricing/projectsMortgage', query: row});
           }
           if(row.applyIstoStatus == 7){
            // 发行申请中
               this.$router.push({name:'users-Customer/projects/projects-OnPricing/publishCompute', query: row});
           }
           if(row.applyIstoStatus == 8){
            // 资产发行
               this.$router.push({name:'users-Customer/projects/projects-OnPricing/assetsPublish', query: row});
           }

        }else{
          if(row.status == 1){
            //sto资格初审
            this.$router.push({name:'users-Customer/projects-audit/first', query: row});
          }
          if(row.status == 4){
            // sto复审
            this.$router.push({name:'users-Customer/projects-audit/retry', query: row});
          }
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  .header {
    margin-top: 30px;
  }

  .table-box {
    width: 98%;
  }
</style>
